package com.qf.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.qf.feign.CacheFeignClient;
import com.qf.pojo.Books;
import com.qf.service.IBooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/books")
public class BooksController {
    private CacheFeignClient cacheFeignClient;


    private IBooksService booksService;
    @Autowired
    public void setCacheFeignClient(CacheFeignClient cacheFeignClient) {
        this.cacheFeignClient = cacheFeignClient;
    }

    @Autowired
    public void setBooksService(IBooksService booksService) {
        this.booksService = booksService;
    }

    @GetMapping("/books")
    public List<Books> findAll() throws JsonProcessingException {
        System.out.println("来查书了");
      return   booksService.findAll();
    }

    @PostMapping("/testhset")
    public int testHset(String key,String field,String value){
        System.out.println(key+" "+field+" "+value);
        return cacheFeignClient.hSet(key,field,value);
    }


    @PostMapping("/testhmset")
    public int testHset(String key){

        Map hashMap=new HashMap();
        hashMap.put("name", "哎");
        hashMap.put("info", "閡");
        System.out.println("进来了");
        int i = cacheFeignClient.hMSet(key, hashMap);
        return i;
    }

    @GetMapping("/getall/{key}")
    public Map getAll(@PathVariable String key){
        Map map = cacheFeignClient.hGetAll(key);
        return map;
    }

}
